//
//  AXFDiscountCell.m
//  爱鲜蜂
//
//  Created by HH on 16/11/4.
//  Copyright © 2016年 胡浩. All rights reserved.
//

#import "AXFDiscountCell.h"
#import "AXFDiscountLayout.h"
#import "AXFPictureCell.h"
#import "AXFCommonModel.h"

static NSString *cellID = @"cellID";
static NSString *AXFPictureCellID = @"AXFPictureCellID";

@interface AXFDiscountCell ()<UICollectionViewDataSource>

@property (nonatomic,weak)UICollectionView *collectionView;

@property (nonatomic,strong)NSArray<AXFCommonModel *> *modelArr;

@end

@implementation AXFDiscountCell

- (void)setupUI
{
    AXFDiscountLayout *layout = [[AXFDiscountLayout alloc] init];
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    
    self.collectionView = collectionView;
    
    collectionView.backgroundColor = [UIColor whiteColor];
    
    collectionView.showsHorizontalScrollIndicator = NO;
    
    [collectionView registerClass:[AXFPictureCell class] forCellWithReuseIdentifier:AXFPictureCellID]
    ;
    collectionView.dataSource = self;
    
    [self.contentView addSubview:collectionView];
    
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.modelArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    AXFPictureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:AXFPictureCellID forIndexPath:indexPath];
    
    cell.model = self.modelArr[indexPath.item];
    
    cell.backgroundColor = [UIColor whiteColor];
    
    return cell;
}

- (void)setDisCountArr:(NSArray<NSDictionary *> *)disCountArr
{
    _disCountArr = disCountArr;
    
    NSMutableArray<AXFCommonModel *> *tempArr = [NSMutableArray array];
    [disCountArr enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSDictionary *activityDict = obj[ACTIVITY];
        
        AXFCommonModel *model = [AXFCommonModel yy_modelWithDictionary:activityDict];
        [tempArr addObject:model];
    }];
    
    self.modelArr = tempArr.copy;
}

- (void)setModelArr:(NSArray<AXFCommonModel *> *)modelArr
{
    _modelArr = modelArr;
    
    [self.collectionView reloadData];
}

@end
